package myreactor;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;

public class BusinessHandler extends AbstractHandler{

	@Override
	public void handle(SelectionKey selectionKey) {
		
		if(selectionKey.isReadable()) {
			ByteBuffer buffer = ByteBuffer.allocate(1024);
			SocketChannel socketChannel = (SocketChannel) selectionKey.channel();
			try {
				socketChannel.read(buffer);
				buffer.flip();
				String threadName = Thread.currentThread().getName();
				System.out.println(new String(buffer.array(),0,buffer.limit())+"_"+threadName);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
